const BaseHandler     = require('../base-handler');
const HTTP_VERBS      = require('../../../constants').HTTP_VERBS;

class WeiboAuthorizeHandler extends BaseHandler {

    get pattern() {
        return "/weibo/authorized";
    }

    doGET(request, response) {

        this.Controller.handleWeiboAuthorization(request.query, request.session.user.id, (result) => {
            if (result && result.success) {
                result.data = {
                    social_id: result.data.app_id,
                    type: 'weibo'
                };
            }
            response.render('console/authorize', result);
        });
    }

    doPOST(request, response) {
        response.end('OK');
    }

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
    }
}

module.exports = WeiboAuthorizeHandler;